<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis内存优化完全指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #2d3748;
            color: #e2e8f0;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            box-shadow: 0 10px 20px rgba(245, 87, 108, 0.3);
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
            box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3);
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            margin: 30px 0;
            text-align: center;
        }
        
        .strategy-card {
            background: white;
            border-radius: 12px;
            padding: 24px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
            border: 1px solid #e2e8f0;
        }
        
        .strategy-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
            border-color: #667eea;
        }
        
        .number-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            font-weight: 600;
            margin-right: 12px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                Redis内存优化完全指南
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                掌握高性能内存数据库的优化艺术
            </p>
            <div class="flex justify-center space-x-8 text-sm md:text-base">
                <div class="flex items-center">
                    <i class="fas fa-memory mr-2"></i>
                    <span>内存管理</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-tachometer-alt mr-2"></i>
                    <span>性能优化</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-database mr-2"></i>
                    <span>数据结构</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">作</span>为一个高性能的内存数据库，Redis广泛应用于各种需要快速数据访问的场景中，比如缓存、会话管理、实时统计等。然而，随着数据量的增长和应用复杂度的提高，Redis的内存使用也会变得越来越紧张。如果不加以合理管理和优化，内存消耗可能会迅速达到服务器的限制，从而影响系统的稳定性和性能。
            </p>
            <div class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="text-center">
                    <div class="feature-icon mx-auto">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">性能提升</h3>
                    <p class="text-gray-600">通过优化内存使用，显著提升Redis响应速度</p>
                </div>
                <div class="text-center">
                    <div class="feature-icon mx-auto">
                        <i class="fas fa-shield-alt"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">稳定可靠</h3>
                    <p class="text-gray-600">避免内存溢出，确保系统稳定运行</p>
                </div>
                <div class="text-center">
                    <div class="feature-icon mx-auto">
                        <i class="fas fa-coins"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">成本优化</h3>
                    <p class="text-gray-600">合理利用资源，降低硬件成本</p>
                </div>
            </div>
        </div>

        <!-- Memory Optimization Mind Map -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 section-title">Redis内存优化全景图</h2>
            <div class="mermaid">
                graph TD
                    A[Redis内存优化] --> B[内存使用分析]
                    A --> C[数据结构优化]
                    A --> D[内存管理参数调优]
                    A --> E[数据压缩]
                    A --> F[热冷数据分离]
                    A --> G[定期清理]
                    
                    B --> B1[INFO MEMORY命令]
                    B --> B2[大键分析]
                    B --> B3[内存碎片分析]
                    
                    C --> C1[字符串优化]
                    C --> C2[列表优化]
                    C --> C3[集合优化]
                    C --> C4[哈希优化]
                    
                    D --> D1[maxmemory设置]
                    D --> D2[淘汰策略]
                    D --> D3[碎片整理]
                    
                    E --> E1[Gzip压缩]
                    E --> E2[Snappy压缩]
                    E --> E3[LZ4压缩]
                    
                    F --> F1[多层存储]
                    F --> F2[缓存淘汰]
                    F --> F3[数据迁移]
                    
                    G --> G1[过期策略]
                    G --> G2[主动清理]
                    G --> G3[定时任务]
            </div>
        </div>

        <!-- Memory Analysis Section -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 section-title">内存使用分析</h2>
            <p class="text-lg text-gray-700 mb-6">
                在进行Redis内存优化时，首先需要对内存使用进行全面而深入的分析。通过内存使用分析，我们可以明确当前Redis实例的内存消耗情况，找出内存使用的热点和潜在问题。
            </p>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                <div class="strategy-card">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <span class="number-badge">1</span>
                        内存使用概览
                    </h3>
                    <p class="text-gray-600 mb-3">使用<code class="bg-gray-100 px-2 py-1 rounded">INFO MEMORY</code>命令获取内存使用概况，包括总内存使用量、分配器内存使用量、内存碎片率等关键指标。</p>
                    <div class="code-block text-sm">
                        redis-cli INFO MEMORY
                    </div>
                </div>
                
                <div class="strategy-card">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <span class="number-badge">2</span>
                        大键分析
                    </h3>
                    <p class="text-gray-600 mb-3">识别占用大量内存的大键，考虑分片存储或改变数据结构以减少内存占用。</p>
                    <div class="code-block text-sm">
                        redis-cli --bigkeys
                    </div>
                </div>
            </div>

            <div class="highlight-box">
                <h4 class="text-xl font-semibold mb-2">
                    <i class="fas fa-lightbulb mr-2"></i>优化建议
                </h4>
                <p>定期监控内存使用趋势，使用Prometheus、Grafana等工具绘制内存使用图表，预估未来内存需求，及时进行扩展或优化。</p>
            </div>
        </div>

        <!-- Data Structure Optimization -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 section-title">数据结构优化</h2>
            <p class="text-lg text-gray-700 mb-6">
                不同的数据结构在存储相同数据时，所占用的内存量可能会有显著差异。通过选择合适的数据结构，可以有效减少内存消耗。
            </p>

            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                    <i class="fas fa-font text-3xl text-purple-600 mb-4"></i>
                    <h3 class="text-xl font-semibold mb-2">字符串优化</h3>
                    <ul class="text-gray-700 space-y-2">
                        <li>• 压缩长字符串</li>
                        <li>• 使用SDS紧凑存储</li>
                        <li>• 控制字符串长度</li>
                    </ul>
                </div>
                
                <div class="bg-gradient-to-br from-blue-50 to-cyan-50 p-6 rounded-xl">
                    <i class="fas fa-list text-3xl text-blue-600 mb-4"></i>
                    <h3 class="text-xl font-semibold mb-2">列表优化</h3>
                    <ul class="text-gray-700 space-y-2">
                        <li>• 使用ziplist编码</li>
                        <li>• 控制列表长度</li>
                        <li>• 避免中间操作</li>
                    </ul>
                </div>
                
                <div class="bg-gradient-to-br from-green-50 to-emerald-50 p-6 rounded-xl">